
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Text;

namespace SharpSoft.Data
{
#if !NETSTANDARD1_6
#if NETSTANDARD2_0
    using Microsoft.Data.Sqlite;
    using SqliteFactory = Microsoft.Data.Sqlite.SqliteFactory;
    using CONNECTION = Microsoft.Data.Sqlite.SqliteConnection;
    using CONNECTIONSTRINGBUILDER = Microsoft.Data.Sqlite.SqliteConnectionStringBuilder;
#else

    using System.Data.SQLite;
    using SqliteFactory = System.Data.SQLite.SQLiteFactory; 
    using CONNECTION = System.Data.SQLite.SQLiteConnection;
    using CONNECTIONSTRINGBUILDER = System.Data.SQLite.SQLiteConnectionStringBuilder;
#endif
    using SharpSoft.Data.GSQL;
    using System.ComponentModel;
    using System.IO;

    [DisplayName("Sqlite数据库")]
    public class Sqlite : Database
    {
        public Sqlite(string p_connstr) : base(SqliteFactory.Instance, p_connstr)
        {

        }
        public static Database CreateSchema(string schemaName)
        {
#if NETSTANDARD2_0
            File.Create(schemaName).Dispose();
#else
            SQLiteConnection.CreateFile(schemaName);
#endif
            return new Sqlite(CreateConnectionString(schemaName,0,"","",""));
        }
        

        public static string CreateConnectionString(string server, int port, string defdb, string uid, string pwd)
        {
            StringBuilder sb = new StringBuilder();
            CONNECTIONSTRINGBUILDER.AppendKeyValuePair(sb, "DataSource", server);
           // CONNECTIONSTRINGBUILDER.AppendKeyValuePair(sb, "Version", "3");
            if (!string.IsNullOrEmpty(pwd))
            {
                CONNECTIONSTRINGBUILDER.AppendKeyValuePair(sb, "Password", pwd); 
            }
            return sb.ToString();
          
        }

        protected override SQLTextGenerator SQLTextGenerator()
        {
            return new SqliteTextGenerator();
        }
    }
#endif
}
